package main

import (
	"fmt"
	"log"
	"net/http"
	"net/http/pprof"
	"os"
	"time"
)

func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/debug/pprof/", pprof.Index)
	mux.HandleFunc("/debug/pprof/profile", pprof.Index)
	mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
	mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
	mux.HandleFunc("/", rtHandler)
	s := &http.Server{
		Addr:           ":80",
		Handler:        mux,
		ReadTimeout:    10 * time.Second,
		WriteTimeout:   10 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}

	err := s.ListenAndServe()
	if err != nil {
		log.Fatal(err)
	}

}

func rtHandler(writer http.ResponseWriter, request *http.Request) {
	header := request.Header
	if len(header) > 0 {
		for k, v := range header {
			fmt.Printf("%s=%s\n", k, v[0])
		}
	}

	//environ := os.Environ()
	//for _, v := range environ {
	//	//fmt.Println(v)
	//	writer.Write([]byte(v))
	//}

	writer.Header().Add("GOPATH", os.Getenv("GOPATH"))
	writer.Header().Add("VERSION", os.Getenv("VERSION"))
	writer.Write([]byte("hello world"))
	writer.WriteHeader(http.StatusOK)

}
